package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.MyCircleItem;
import com.sam.im.heiqun.entities.MyGiftItem;
import com.yuyh.library.utils.GlideUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by wangguodong on 2017/8/21.
 */

public class GiftSendAdapter extends RecyclerView.Adapter <GiftSendAdapter.ViewHold>{
    private static final String TAG = "SendCircleActivity";
    private Context mContext ;
    private List<MyGiftItem.ListBean> datas ;

    public GiftSendAdapter(Context mContext, List<MyGiftItem.ListBean> datas){
        this.mContext = mContext ;
//        this.datas = null==datas?new String[0]:datas ;
        this.datas = datas ;
    }

    @Override
    public GiftSendAdapter.ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View headView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_gift_list, parent, false);
        return new ViewHold(headView);
    }

    @Override
    public void onBindViewHolder(GiftSendAdapter.ViewHold holder, int position) {
        MyGiftItem.ListBean listBean = datas.get(position);
        GlideUtils.loadCircleImage(mContext, listBean.getHeadUrl(),holder.image_head);
        String name = "" ;
        try {
            JSONObject json = JSON.parseObject(listBean.getGiftContent());
            name = json.getString("name");
        }catch (Exception e){e.printStackTrace();}

        if ("".equals(name))name = mContext.getResources().getString(R.string.gift);

        holder.txt_name.setText(listBean.getName()+mContext.getResources().getString(R.string.song)+name+"1"+mContext.getResources().getString(R.string.entrie));

        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d1=new Date(Long.parseLong(listBean.getCreateTime()));
        String t1=format.format(d1);
        holder.txt_time.setText(t1);

    }

    @Override
    public int getItemCount() {
        return null==datas?0:datas.size();
    }

    class ViewHold extends RecyclerView.ViewHolder{

        ImageView image_head ;
        TextView txt_name ;
        TextView txt_time ;

        public ViewHold(View itemView) {
            super(itemView);
            image_head = (ImageView) itemView.findViewById(R.id.image_head);
            txt_name = (TextView) itemView.findViewById(R.id.txt_name);
            txt_time = (TextView) itemView.findViewById(R.id.txt_time);
        }
    }

}
